<template>
  <div class="common-layout">
    <!-- 头部导航栏 -->
    <el-header class="header" height="60px">
      <div class="logo">职途导师</div>
      <el-menu 
        mode="horizontal" 
        :default-active="activeMenu" 
        class="nav-menu"
        router
      >
        <el-menu-item index="/home">主页</el-menu-item>
        <el-menu-item index="/pending-interviews">待面试列表</el-menu-item>
        <el-menu-item index="/interview-history">面试历史记录</el-menu-item>
      </el-menu>
      <div class="user-info">
        <el-dropdown>
          <span class="user-dropdown">
            <el-avatar :size="32" src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png" />
            <span class="username">{{ username || '用户名' }}</span>
          </span>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item>个人中心</el-dropdown-item>
              <el-dropdown-item>设置</el-dropdown-item>
              <el-dropdown-item divided @click="handleLogout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </el-header>
    
    <!-- 内容主体 -->
    <el-main class="main-content">
      <slot></slot>
    </el-main>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { useRouter, useRoute } from 'vue-router';

const props = defineProps<{
  defaultActiveMenu?: string;
}>();

const router = useRouter();
const route = useRoute();
const activeMenu = ref(props.defaultActiveMenu || route.path);
const username = ref('');

// 获取用户名
onMounted(() => {
  username.value = localStorage.getItem('username') || '';
});

// 退出登录
const handleLogout = () => {
  localStorage.removeItem('isLoggedIn');
  localStorage.removeItem('username');
  localStorage.removeItem('userid');
  router.push('/login');
};
</script>

<style>
/* 全局样式重置 */
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
}

#app {
  height: 100%;
  width: 100%;
}
</style>

<style scoped>
.common-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

.header {
  display: flex;
  align-items: center;
  padding: 0 20px;
  background-color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  position: sticky;
  top: 0;
  z-index: 999;
  min-height: 60px;
  flex-shrink: 0;
}

.logo {
  font-size: 22px;
  font-weight: bold;
  color: #1890ff;
  margin-right: 40px;
  white-space: nowrap;
}

.nav-menu {
  flex: 1;
  border-bottom: none;
}

.user-info {
  margin-left: 20px;
  white-space: nowrap;
}

.user-dropdown {
  display: flex;
  align-items: center;
  cursor: pointer;
}

.username {
  margin-left: 8px;
}

.main-content {
  padding: 20px;
  background-color: #f5f7fa;
  flex: 1;
  overflow-y: auto;
  height: calc(100vh - 60px);
  box-sizing: border-box;
}

/* 媒体查询适配不同屏幕尺寸 */
@media (max-width: 768px) {
  .header {
    padding: 0 10px;
  }
  
  .logo {
    font-size: 18px;
    margin-right: 20px;
  }
  
  .main-content {
    padding: 15px;
  }
}

@media (max-width: 576px) {
  .logo {
    font-size: 16px;
    margin-right: 10px;
  }
  
  .username {
    display: none;
  }
  
  .main-content {
    padding: 10px;
  }
}
</style> 